/*
 * 软件著作权：北京康兰尚德数据科技有限公司
 * 项目名称：康兰数据购物中心分析平台
 *
 * NAME : DataFetcherFromDB.java
 *
 * PURPOSE : 用户管理数据库访问
 *
 * AUTHOR : EEDATA/ywb
 *
 *
 * 创建日期: 2013-12-2
 * HISTORY：2013-12-3,4
 * 变更日期 
 */
package com.redwolfsoft.libshoppingserver.datafetcher;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import pojo.EcpBsTerritoryinfo;
import pojo.EcpFkFeedback;
import pojo.EcpGwcActivity;
import pojo.EcpGwcShopping;
import pojo.EcpGwcStore;
import pojo.EcpPpBrand;
import pojo.EcpPpBrandcomment;
import pojo.EcpPpNewbrand;
import pojo.EcpPpOnlinestore;
import pojo.EcpPpPraise;
import pojo.EcpPpStory;
import pojo.EcpPpStorycomment;
import pojo.EcpScUsercollect;
import pojo.EcpYhUser;
import pojo.ShopSort;

import com.redwolfsoft.libshoppingserver.brand.BrandAuthorizedShopInfo;
import com.redwolfsoft.libshoppingserver.brand.BrandInfo;
import com.redwolfsoft.libshoppingserver.brand.BrandShopArea;
import com.redwolfsoft.libshoppingserver.brand.BrandShopInfo;
import com.redwolfsoft.libshoppingserver.brand.BrandStoryInfo;
import com.redwolfsoft.libshoppingserver.brand.CommentInfo;
import com.redwolfsoft.libshoppingserver.brand.CountryCategory;
import com.redwolfsoft.libshoppingserver.brand.NewProductInfo;
import com.redwolfsoft.libshoppingserver.brand.PriceInfo;
import com.redwolfsoft.libshoppingserver.brand.RecommendCategoryInfo;
import com.redwolfsoft.libshoppingserver.brand.Story;
import com.redwolfsoft.libshoppingserver.favorite.FavoriteBrandItemInfo;
import com.redwolfsoft.libshoppingserver.favorite.FavoriteShoppingcenterItemInfo;
import com.redwolfsoft.libshoppingserver.shoppingcenter.ShoppingCenterBrandInfo;
import com.redwolfsoft.libshoppingserver.shoppingcenter.ShoppingCenterInfo;
import com.redwolfsoft.libshoppingserver.shoppingcenter.ShoppingCenterPromotionInfo;
import com.redwolfsoft.libshoppingserver.shoppingcenter.ShoppingCenterShopFloorInfo;
import com.redwolfsoft.libshoppingserver.shoppingcenter.ShoppingCenterShopInfo;

import dao.ActivityDaoImpl;
import dao.BrandDaoImpl;
import dao.CollectDaoImpl;
import dao.CommentDaoImpl;
import dao.FeedBackDaoImpl;
import dao.NewBrandDaoImpl;
import dao.OnlinestoreDaoImpl;
import dao.PraiseDaoImpl;
import dao.ShopDaoImpl;
import dao.StoreDaoImpl;
import dao.StoryDaoImpl;
import dao.UserDaoImpl;

/**
 * 实现类
 * 
 * @author ywb
 */

public class DataFetcherFromDB implements DataFetcher {

	/**
	 * ppt page3:获取以国家分类的品牌列表
	 */
	@Override
	public List<CountryCategory> getCountryCategoryBrandInfoList() {// 一
		BrandDaoImpl brandDao = new BrandDaoImpl();

		List<EcpBsTerritoryinfo> coulist = brandDao.selectCountry();

		List<CountryCategory> countryCategorieslist = new ArrayList<CountryCategory>();

		for (EcpBsTerritoryinfo ecpBsTerritoryinfo : coulist) {
			List<EcpPpBrand> list = brandDao.selectBrand(ecpBsTerritoryinfo
					.getTerritoryid());

			List<BrandInfo> brandlist = new ArrayList<BrandInfo>();

			for (EcpPpBrand ecpPpBrand : list) {
				String newString = null;
				if (ecpPpBrand.getPicpath() != null
						&& ecpPpBrand.getPicpath() != "")
					newString = ecpPpBrand.getPicpath().substring(
							ecpPpBrand.getPicpath().lastIndexOf("/") + 1);
				ecpPpBrand.getTerritoryid();
				BrandInfo brandInfo = new BrandInfo(ecpPpBrand.getBrandid(),
						ecpPpBrand.getChname(), ecpPpBrand.getPicpath(), null,
						newString);
				brandlist.add(brandInfo);
			}

			CountryCategory category = new CountryCategory(
					ecpBsTerritoryinfo.getTerritoryid(),
					ecpBsTerritoryinfo.getCountry(), brandlist);
			countryCategorieslist.add(category);

		}

		return countryCategorieslist;
	}

	/**
	 * ppt page4：获取特定品牌的新品列表
	 */
	@Override
	public List<NewProductInfo> getNewProductInfoList(String brandid) {// 二
		NewBrandDaoImpl newBrandDao = new NewBrandDaoImpl();

		List<EcpPpNewbrand> newbraList = newBrandDao.selectNewBrand(brandid);

		List<NewProductInfo> newList = new ArrayList<NewProductInfo>();

		for (EcpPpNewbrand ecpPpBrandother : newbraList) {
			int numReviews = newBrandDao.selectCommBrandothersNum(""
					+ ecpPpBrandother.getBraotherid());// 在评论表中查询评论个数
			int numApplaud = newBrandDao.selectPriseNum(""
					+ ecpPpBrandother.getBraotherid());// 在赞表中查询赞个数

			String smallname = null;
			String bigname = null;
			String smallpath = ecpPpBrandother.getSmallpicpath();
			String bigpath = ecpPpBrandother.getBigpicpath();

			if (smallpath != null && smallpath != "")
				smallname = smallpath.substring(smallpath.lastIndexOf("/") + 1);
			if (bigpath != null && bigpath != "")
				bigname = bigpath.substring(bigpath.lastIndexOf("/") + 1);

			NewProductInfo newProductInfo = new NewProductInfo(""
					+ ecpPpBrandother.getBraotherid(), null,
					ecpPpBrandother.getSmallpicpath(), null, smallname,
					numReviews, numApplaud, ecpPpBrandother.getBigpicpath(),
					bigname);
			newProductInfo.hasApplauded = false;// 写死
			// 描述
			List<PriceInfo> priceList = new ArrayList<PriceInfo>();
			String des = ecpPpBrandother.getDescription();
			String[] desChar = {};
			if (des != null)
				desChar = des.split("<br>");
			for (int i = 0; i < desChar.length; i++) {
				PriceInfo priceInfo = new PriceInfo(desChar[i], null, 0);
				priceList.add(priceInfo);
			}
			newProductInfo.priceList = priceList;

			newList.add(newProductInfo);

		}

		return newList;
	}

	/**
	 * ppt page10,page11：获取特定品牌的在特定国家的各个城市区域的专卖店列表
	 */
	@Override
	public List<BrandShopArea> getBrandShopAreaList(String countryid,
			String brandid, double longitide, double latitude, int page) {// 三
		StoreDaoImpl storeDao = new StoreDaoImpl();

		List<String> shopidList = storeDao.selectShopid(brandid);

		List<BrandShopArea> brandshopList = new ArrayList<BrandShopArea>();

		for (String shopid : shopidList) {
			List<BrandShopInfo> brandShopInfoList = new ArrayList<BrandShopInfo>();

			List<EcpGwcStore> storeList = storeDao.selectStroe(shopid);

			EcpGwcShopping shop = storeDao.selectShop(shopid);

			for (EcpGwcStore ecpGwcStore : storeList) {

				BrandShopInfo brandshopInfo = new BrandShopInfo(
						ecpGwcStore.getStoreid(), shop.getName(), null,
						ecpGwcStore.getLocation(), ecpGwcStore.getAddress(),
						ecpGwcStore.getPhone(), ecpGwcStore.getPicpath(),
						shop.getLongitude(), shop.getLatitude());
				brandShopInfoList.add(brandshopInfo);
			}

			String territoryid = storeDao.selectTerritoryid(shopid);
			String cityname = storeDao.selectCity(territoryid);

			BrandShopArea brandShopArea = new BrandShopArea(territoryid,
					cityname, brandShopInfoList);
			brandshopList.add(brandShopArea);

		}

		return brandshopList;

	}

	/**
	 * ppt page9：获取特定新品的评价列表
	 */
	@Override
	public List<CommentInfo> getBrandReviewInfoList(String newproductid) {// 四
		CommentDaoImpl commentDao = new CommentDaoImpl();

		List<CommentInfo> bList = new ArrayList<CommentInfo>();

		List<EcpPpBrandcomment> brandcommentList = commentDao
				.selectNewBrandcomments(newproductid);
		for (EcpPpBrandcomment ecpPpBrandcomment : brandcommentList) {
			String usernick = commentDao.selectUsers(ecpPpBrandcomment
					.getUserid());
			CommentInfo bInfo = new CommentInfo(usernick, ecpPpBrandcomment
					.getComdate().getTime(), ecpPpBrandcomment.getContent());
			bList.add(bInfo);

		}

		return bList;
	}

	/**
	 * ppt page9：添加对特定新品的评价 添加成功返回true，否则返回false
	 */
	@Override
	public boolean addReview(String user, String deviceId, String review,
			String newproductid) {// 五
		boolean flag = false;

		if (user != null && newproductid != null) {

			CommentDaoImpl commentDao = new CommentDaoImpl();

			EcpPpBrandcomment bracom = new EcpPpBrandcomment();
			bracom.setContent(review);

			Timestamp ts = new Timestamp(System.currentTimeMillis());
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String tsStr = format.format(new Date());
			ts = Timestamp.valueOf(tsStr);

			bracom.setComdate(ts);
			bracom.setUserid(Integer.parseInt(user));
			bracom.setBraotherid(Integer.parseInt(newproductid));
			flag = commentDao.insertNewBrandComment(bracom);
		}

		return flag;
	}

	/**
	 * ppt page13：获取特定品牌授权网店列表
	 */
	@Override
	public List<BrandAuthorizedShopInfo> getAuthorizedBrandEShopInfoList(
			String brandid) {// 六
		OnlinestoreDaoImpl onlinestoreDao = new OnlinestoreDaoImpl();

		List<EcpPpOnlinestore> onlinelist = onlinestoreDao
				.selectOnlinestore(brandid);

		List<BrandAuthorizedShopInfo> list = new ArrayList<BrandAuthorizedShopInfo>();

		for (EcpPpOnlinestore onlist : onlinelist) {
			BrandAuthorizedShopInfo info = new BrandAuthorizedShopInfo(
					onlist.getName(), onlist.getUrl());
			list.add(info);
		}

		return list;
	}

	/**
	 * ppt page17：获取购物中心列表
	 * 
	 * @param type
	 *            : 为0时，表示要获取附近购物中心列表，
	 * @param longititue
	 *            和 @param latitude 表示经纬度坐标 为1时表示获取推荐的列表，其他参数无意义;已废弃
	 *            为2时，表示搜索某地附近列表，
	 * @param address为待搜索目标
	 *            参见HttpConstants.SHOPPINGCENTER_TYPE_NEARBY
	 *            SHOPPINGCENTER_TYPE_RECOMMEND SHOPPINGCENTER_TYPE_SEARCH
	 */
	@Override
	public List<ShoppingCenterInfo> getShoppingCenterInfoList(int type,
			double longititue, double latitude, String address, int page,String userid) {// 七
		ShopDaoImpl shopDao = new ShopDaoImpl();

		List<ShoppingCenterInfo> shoppingCenterInfos = new ArrayList<ShoppingCenterInfo>();

		switch (type) {
		case 0:
			List<ShopSort> shopList = shopDao.selectShopByl(longititue,
					latitude);
			for (int i = 0; i < shopList.size(); i++) {
				ShoppingCenterInfo shoppingCenterInfo = new ShoppingCenterInfo(
						shopList.get(i).getShopid(), shopList.get(i).getName(),
						null, false);
				shoppingCenterInfo.longititude = shopList.get(i).getLongitude();
				shoppingCenterInfo.latitude = shopList.get(i).getLatitude();
				shoppingCenterInfo.address = shopList.get(i).getAddress();
				shoppingCenterInfo.tel = shopList.get(i).getPhone();
				shoppingCenterInfo.serviceSlot = shopList.get(i).getOpenhour();

				shoppingCenterInfos.add(shoppingCenterInfo);
			}

			break;

		case 2:
			List<ShopSort> shopList1 = shopDao.selectShop(address, longititue,
					latitude);
			for (ShopSort shopSort : shopList1) {
				ShoppingCenterInfo shoppingCenterInfo = new ShoppingCenterInfo(
						shopSort.getShopid(), shopSort.getName(), null, false);
				shoppingCenterInfo.longititude = shopSort.getLongitude();
				shoppingCenterInfo.latitude = shopSort.getLatitude();
				shoppingCenterInfo.address = shopSort.getAddress();
				shoppingCenterInfo.tel = shopSort.getPhone();
				shoppingCenterInfo.serviceSlot = shopSort.getOpenhour();

				shoppingCenterInfos.add(shoppingCenterInfo);
			}

			break;

		default:
			break;
		}

		return shoppingCenterInfos;
	}

	/**
	 * ppt page19：获取购物中心列表促销活动列表
	 */
	@Override
	public List<ShoppingCenterPromotionInfo> getShoppingCenterPromotionInfoList(
			String shoppingcenterId) {// 八
		ActivityDaoImpl activityDao = new ActivityDaoImpl();

		List<EcpGwcActivity> list = activityDao
				.selectActivity(shoppingcenterId);

		List<ShoppingCenterPromotionInfo> infolist = new ArrayList<ShoppingCenterPromotionInfo>();

		for (EcpGwcActivity ecpGwcActivity : list) {
			ShoppingCenterPromotionInfo info = new ShoppingCenterPromotionInfo(
					ecpGwcActivity.getContent());
			infolist.add(info);
		}

		return infolist;
	}

	/**
	 * ppt page20：获取特定购物中心店铺列表
	 */
	@Override
	public List<ShoppingCenterShopInfo> getShoppingCenterShopInfoList(
			String shoppingcenterId) {// 九
		StoreDaoImpl storeDao = new StoreDaoImpl();

		List<String> sortList = storeDao.selectStoreSort(shoppingcenterId);

		List<ShoppingCenterShopInfo> sortBeanList = new ArrayList<ShoppingCenterShopInfo>();

		for (String sort : sortList) {
			List<EcpGwcStore> storeList = storeDao.selectStoreBySort(sort);

			List<ShoppingCenterBrandInfo> storeBeanList = new ArrayList<ShoppingCenterBrandInfo>();

			for (EcpGwcStore ecpGwcStore : storeList) {
				ShoppingCenterBrandInfo storeBean = new ShoppingCenterBrandInfo(
						ecpGwcStore.getBrandid(), ecpGwcStore.getName(),
						ecpGwcStore.getLocation());
				storeBeanList.add(storeBean);
			}

			String sortname = storeDao.selectSortName(sort);

			ShoppingCenterShopInfo sortBean = new ShoppingCenterShopInfo(
					sortname, storeBeanList.size(), storeBeanList);
			sortBeanList.add(sortBean);
		}

		return sortBeanList;

	}

	/**
	 * ppt page18：获取特定购物中心品牌列表
	 */
	@Override
	public List<ShoppingCenterBrandInfo> getShoppingCenterBrandInfoList(
			String shoppingcenterId) {// 十
		StoreDaoImpl storeDao = new StoreDaoImpl();

		List<EcpGwcStore> list = storeDao.selectStroe(shoppingcenterId);

		List<ShoppingCenterBrandInfo> infolist = new ArrayList<ShoppingCenterBrandInfo>();

		for (EcpGwcStore ecpGwcStore : list) {
			ShoppingCenterBrandInfo info = new ShoppingCenterBrandInfo(
					ecpGwcStore.getBrandid(), ecpGwcStore.getName(),
					ecpGwcStore.getLocation());
			infolist.add(info);
		}

		return infolist;
	}

	/**
	 * 获取收藏的购物中心列表
	 */
	@Override
	public List<FavoriteShoppingcenterItemInfo> getFavoritedShoppingCenterList(
			String user, String deviceId) {// 十一
		CollectDaoImpl collectDao = new CollectDaoImpl();

		List<FavoriteShoppingcenterItemInfo> infoList = new ArrayList<FavoriteShoppingcenterItemInfo>();

		List<String> brandidList = collectDao.selectBrandOrShopId(
				Integer.parseInt(user), 2);
		for (String shopid : brandidList) {
			EcpGwcShopping shop = collectDao.selectShop(shopid);

			FavoriteShoppingcenterItemInfo shoppingCenterInfo = new FavoriteShoppingcenterItemInfo(
					shop.getShopid(), shop.getName(), null);
			infoList.add(shoppingCenterInfo);
		}

		return infoList;
	}

	/**
	 * 获取收藏的品牌列表
	 */
	@Override
	public List<FavoriteBrandItemInfo> getFavoritedBrandInfoList(String user,
			String deviceId) {// 十二
		CollectDaoImpl collectDao = new CollectDaoImpl();

		List<FavoriteBrandItemInfo> infoList = new ArrayList<FavoriteBrandItemInfo>();

		List<String> brandidList = collectDao.selectBrandOrShopId(
				Integer.parseInt(user), 1);
		for (String brandid : brandidList) {
			EcpPpBrand brand = collectDao.selectBrand(brandid);

			FavoriteBrandItemInfo brandInfo = new FavoriteBrandItemInfo(
					brand.getBrandid(), brand.getChname(), brand.getLogopath());
			infoList.add(brandInfo);

		}

		return infoList;
	}

	/**
	 * 获取品牌故事列表
	 */
	@Override
	public BrandStoryInfo getBrandStoryInfo(String brandid) {// 十三
		StoryDaoImpl storyDao = new StoryDaoImpl();
		List<Story> stories = new ArrayList<Story>();

		List<EcpPpStory> storyList = storyDao.selectStory(brandid);
		for (EcpPpStory ecpPpStory : storyList) {
			Integer bommentnum = storyDao.selectStoryCommentNum(ecpPpStory
					.getStoryid());
			Story story = new Story(ecpPpStory.getStoryid(),
					ecpPpStory.getName(), ecpPpStory.getContent(), ecpPpStory
							.getStorydate().toString(), bommentnum,
					ecpPpStory.getPicpath(), ecpPpStory.getStoreurl());
			stories.add(story);
		}

		EcpPpBrand brand = storyDao.selectBrand(brandid);

		BrandStoryInfo brandStoryInfo = null;

		if (brand != null) {
			brandStoryInfo = new BrandStoryInfo(brand.getLogopath(),
					brand.getIntroduce(), stories);
		}

		return brandStoryInfo;
	}

	/**
	 * 推荐列表
	 */
	@Override
	public List<RecommendCategoryInfo> getRecommendCategoryInfo(
			double longitide, double latitude, int page,String userid) {// 十四
		ShopDaoImpl shopDao = new ShopDaoImpl();

		List<RecommendCategoryInfo> recommendCategoryInfoList = new ArrayList<RecommendCategoryInfo>();

		List<String> disidList = shopDao.selectShopDistrict();
		for (String id : disidList) {
			List<ShoppingCenterInfo> shoppingCenterInfoList = new ArrayList<ShoppingCenterInfo>();

			List<ShopSort> shopList = shopDao.selectShopBySort(id, longitide,
					latitude);
			for (ShopSort shopSort : shopList) {
				ShoppingCenterInfo shoppingCenterInfo = new ShoppingCenterInfo(
						shopSort.getShopid(), shopSort.getName(), null, false);
				shoppingCenterInfo.longititude = shopSort.getLongitude();
				shoppingCenterInfo.latitude = shopSort.getLatitude();
				shoppingCenterInfo.address = shopSort.getAddress();
				shoppingCenterInfo.tel = shopSort.getPhone();
				shoppingCenterInfo.serviceSlot = shopSort.getOpenhour();

				shoppingCenterInfoList.add(shoppingCenterInfo);
			}

			String disname = shopDao.selectDistrictName(id);

			RecommendCategoryInfo recommendCategoryInfo = new RecommendCategoryInfo(
					id, disname, shoppingCenterInfoList);
			recommendCategoryInfoList.add(recommendCategoryInfo);

		}

		return recommendCategoryInfoList;
	}

	/**
	 * 获取楼层分类列表
	 */
	@Override
	public List<ShoppingCenterShopFloorInfo> getShoppingCenterShopFloorInfoList(
			String shoppingcenterid) {// 十五
		List<ShoppingCenterShopFloorInfo> shopFloorInfoList = new ArrayList<ShoppingCenterShopFloorInfo>();

		StoreDaoImpl storeDao = new StoreDaoImpl();
		List<String> flooList = storeDao.selectFloor(shoppingcenterid);
		for (String floor : flooList) {
			List<ShoppingCenterBrandInfo> shoppingCenterBrandInfoList = new ArrayList<ShoppingCenterBrandInfo>();

			List<EcpGwcStore> storeList = storeDao.selectStoreByFloor(floor);
			for (EcpGwcStore ecpGwcStore : storeList) {
				ShoppingCenterBrandInfo shoppingCenterBrandInfo = new ShoppingCenterBrandInfo(
						ecpGwcStore.getBrandid(), ecpGwcStore.getName(),
						ecpGwcStore.getLocation());
				shoppingCenterBrandInfoList.add(shoppingCenterBrandInfo);
			}

			String floorname = storeDao.selectFloorName(floor);

			ShoppingCenterShopFloorInfo shopFloorInfo = new ShoppingCenterShopFloorInfo(
					floorname, shoppingCenterBrandInfoList);
			shopFloorInfoList.add(shopFloorInfo);
		}

		return shopFloorInfoList;
	}

	/**
	 * 注册新用户
	 */
	@Override
	public boolean registerNewUser(String user, String passwd, String deviceid,
			String email, String mobile, String gender, String birthdate) {// 十六
		UserDaoImpl userDao = new UserDaoImpl();

		boolean sex = false;
		if ("0".equals(gender))
			sex = true;

		EcpYhUser user2 = new EcpYhUser(user, passwd, deviceid, email, mobile,
				sex, birthdate);

		return userDao.insertUser(user2);

	}

	/**
	 * 用户登录
	 */
	@Override
	public String login(String email, String passwd, String deviceid) {// 十七
		UserDaoImpl userDao = new UserDaoImpl();

		String result = "-1";
		if (email != null && passwd != null)
			result = userDao.login(email, passwd);

		return result;

	}

	/**
	 * 退出登录
	 */
	@Override
	public boolean logout(String userid, String passwd, String deviceid) {// 十八
		UserDaoImpl userDao = new UserDaoImpl();

		boolean result = false;
		if (userid != null && passwd != null)
			result = userDao.exitlogin(userid, passwd);

		return result;
	}

	/**
	 * 添加故事的评价
	 */
	@Override
	public boolean addStoryComment(String userid, String deviceid,
			String review, String storyid) {// 十九
		boolean flag = false;

		if (userid != null && storyid != null) {
			CommentDaoImpl commentDao = new CommentDaoImpl();

			Timestamp ts = new Timestamp(System.currentTimeMillis());
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String tsStr = format.format(new Date());
			ts = Timestamp.valueOf(tsStr);

			EcpPpStorycomment storycomment = new EcpPpStorycomment(review, ts,
					Integer.parseInt(userid), Integer.parseInt(storyid));

			flag = commentDao.inserStoryComment(storycomment);

		}

		return flag;
	}

	/**
	 * 故事的评价列表
	 */
	@Override
	public List<CommentInfo> getStoryCommentInfoList(String storyid) {// 二十
		CommentDaoImpl commentDao = new CommentDaoImpl();

		List<CommentInfo> bList = new ArrayList<CommentInfo>();

		List<EcpPpStorycomment> storycommentList = commentDao
				.selectStorycomments(storyid);
		for (EcpPpStorycomment ecpPpStorycomment : storycommentList) {
			String usernick = commentDao.selectUsers(ecpPpStorycomment
					.getUserid());
			CommentInfo bInfo = new CommentInfo(usernick, ecpPpStorycomment
					.getComdate().getTime(), ecpPpStorycomment.getContetn());
			bList.add(bInfo);

		}

		return bList;

	}

	/**
	 * 用户userid赞了某个新品
	 */
	@Override
	public boolean applaudNewProduct(String newproductid, String userid) {// 二十一
		boolean flag = false;

		if (newproductid != null && userid != null) {
			PraiseDaoImpl praiseDao = new PraiseDaoImpl();

			Timestamp ts = new Timestamp(System.currentTimeMillis());
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String tsStr = format.format(new Date());
			ts = Timestamp.valueOf(tsStr);

			EcpPpPraise praise = new EcpPpPraise(Integer.parseInt(userid),
					Integer.parseInt(newproductid), ts);

			flag = praiseDao.insertnewbrandPraise(praise);
		}
		return flag;
	}

	/**
	 * 意见反馈
	 */
	@Override
	public boolean addFeedback(String userid, String deviceid, String feedback,
			String qq) {// 二十二
		boolean flag = false;
		FeedBackDaoImpl feedbackDao = new FeedBackDaoImpl();

		Timestamp ts = new Timestamp(System.currentTimeMillis());
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String tsStr = format.format(new Date());
		ts = Timestamp.valueOf(tsStr);

		int user = 0;
		if (userid != null && !userid.equals("-1"))
			user = Integer.parseInt(userid);

		EcpFkFeedback feed = new EcpFkFeedback(feedback, user, qq, ts);

		flag = feedbackDao.insertFeedBack(feed);

		return flag;
	}

	/**
	 * 返回搜索结果 专卖店列表
	 */
	@Override
	public List<BrandShopInfo> getBrandShopInfoList(String address,
			double longitide, double latitude, int page) {// 二十三
		StoreDaoImpl storeDao = new StoreDaoImpl();

		List<BrandShopInfo> brandShopInfoList = new ArrayList<BrandShopInfo>();

		List<ShopSort> shopList = storeDao.selectStoreByAdd(address, longitide,
				latitude);
		for (ShopSort shopSort : shopList) {
			List<EcpGwcStore> storeList = storeDao.selectStroe(shopSort
					.getShopid());
			for (EcpGwcStore ecpGwcStore : storeList) {
				BrandShopInfo brandShopInfo = new BrandShopInfo(
						ecpGwcStore.getStoreid(), shopSort.getName(), null,
						ecpGwcStore.getLocation(), ecpGwcStore.getAddress(),
						ecpGwcStore.getPhone(), ecpGwcStore.getPicpath(),
						shopSort.getLongitude(), shopSort.getLatitude());
				brandShopInfoList.add(brandShopInfo);
			}
		}

		return brandShopInfoList;
	}

	/**
	 * 某用户收藏某购物中心
	 */
	@Override
	public boolean favoriteShoppingCenter(String userid, String deviceid,
			String shoppingcenterid) {// 二十四
		boolean result = false;

		if (userid != null && shoppingcenterid != null) {
			CollectDaoImpl collectDao = new CollectDaoImpl();

			EcpScUsercollect shop = new EcpScUsercollect();
			shop.setUserid(Integer.parseInt(userid));
			shop.setFid(shoppingcenterid);
			shop.setSort(2);
			EcpScUsercollect usercollect = collectDao.selectCollect(shop);

			if (usercollect != null) {
				EcpScUsercollect shopc = new EcpScUsercollect();
				shopc.setShopcolid(usercollect.getShopcolid());
				shopc.setUserid(Integer.parseInt(userid));
				shopc.setFid(shoppingcenterid);
				shopc.setSort(2);
				shopc.setTag(true);
				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				shopc.setCollectdate(formatter.format(new Date()));
				shopc.setCancledate(usercollect.getCancledate());

				result = collectDao.updateCollect(shopc);
			} else {

				EcpScUsercollect shopcollect = new EcpScUsercollect();
				shopcollect.setUserid(Integer.parseInt(userid));
				shopcollect.setFid(shoppingcenterid);
				shopcollect.setSort(2);
				shopcollect.setTag(true);

				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				shopcollect.setCollectdate(formatter.format(new Date()));

				result = collectDao.insertCollect(shopcollect);
			}
		}

		return result;
	}

	/**
	 * 某用户收藏某品牌
	 */
	@Override
	public boolean favoriteBrand(String userid, String deviceid, String brandid) {// 二十五
		boolean result = false;

		if (userid != null && brandid != null) {
			CollectDaoImpl collectDao = new CollectDaoImpl();

			EcpScUsercollect brand = new EcpScUsercollect();
			brand.setUserid(Integer.parseInt(userid));
			brand.setFid(brandid);
			brand.setSort(1);
			EcpScUsercollect usercollect = collectDao.selectCollect(brand);

			if (usercollect != null) {
				EcpScUsercollect brandc = new EcpScUsercollect();
				brandc.setShopcolid(usercollect.getShopcolid());
				brandc.setUserid(Integer.parseInt(userid));
				brandc.setFid(brandid);
				brandc.setSort(1);
				brandc.setTag(true);
				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				brandc.setCollectdate(formatter.format(new Date()));
				brandc.setCancledate(usercollect.getCancledate());

				result = collectDao.updateCollect(brandc);
			} else {

				EcpScUsercollect brandcollect = new EcpScUsercollect();
				brandcollect.setUserid(Integer.parseInt(userid));
				brandcollect.setFid(brandid);
				brandcollect.setSort(1);
				brandcollect.setTag(true);

				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				brandcollect.setCollectdate(formatter.format(new Date()));

				result = collectDao.insertCollect(brandcollect);
			}
		}

		return result;
	}

	/**
	 * 查询某用户是否收藏了某品牌
	 */
	@Override
	public boolean isFavoriteBrand(String userid, String deviceid,
			String brandid) {// 二十六
		boolean result = false;

		if (userid != null && brandid != null) {
			CollectDaoImpl collectDao = new CollectDaoImpl();

			EcpScUsercollect shopcollect = new EcpScUsercollect();
			shopcollect.setUserid(Integer.parseInt(userid));
			shopcollect.setFid(brandid);
			shopcollect.setSort(1);

			result = collectDao.checkCollect(shopcollect);

		}

		return result;
	}

	/**
	 * 查询某用户是否收藏了某购物中心
	 */
	@Override
	public boolean isFavoriteShoppingCenter(String userid, String deviceid,
			String shoppingcenterid) {// 二十七
		boolean result = false;

		if (userid != null && shoppingcenterid != null) {
			CollectDaoImpl collectDao = new CollectDaoImpl();

			EcpScUsercollect shopcollect = new EcpScUsercollect();
			shopcollect.setUserid(Integer.parseInt(userid));
			shopcollect.setFid(shoppingcenterid);
			shopcollect.setSort(2);

			result = collectDao.checkCollect(shopcollect);

		}

		return result;
	}

	/**
	 * 某用户取消收藏某品牌
	 */
	@Override
	public boolean cancelFavoriteBrand(String userid, String deviceid,
			String brandid) {// 二十八
		boolean result = false;

		if (userid != null && brandid != null) {
			CollectDaoImpl collectDao = new CollectDaoImpl();

			EcpScUsercollect shopcollect = new EcpScUsercollect();
			shopcollect.setUserid(Integer.parseInt(userid));
			shopcollect.setFid(brandid);
			shopcollect.setSort(1);
			EcpScUsercollect usercollect = collectDao
					.selectCollect(shopcollect);

			if (usercollect != null) {
				EcpScUsercollect shop = new EcpScUsercollect();
				shop.setShopcolid(usercollect.getShopcolid());
				shop.setUserid(Integer.parseInt(userid));
				shop.setFid(brandid);
				shop.setSort(1);
				shop.setTag(false);
				shop.setCollectdate(usercollect.getCollectdate());
				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				shop.setCancledate(formatter.format(new Date()));

				result = collectDao.updateCollect(shop);
			}

		}

		return result;
	}

	/**
	 * 某用户取消收藏某购物中心
	 */
	@Override
	public boolean cancelFavoriteShoppingcenter(String userid, String deviceid,
			String shoppingcenterid) {// 二十九
		boolean result = false;

		if (userid != null && shoppingcenterid != null) {
			CollectDaoImpl collectDao = new CollectDaoImpl();

			EcpScUsercollect shopcollect = new EcpScUsercollect();
			shopcollect.setUserid(Integer.parseInt(userid));
			shopcollect.setFid(shoppingcenterid);
			shopcollect.setSort(2);
			EcpScUsercollect usercollect = collectDao
					.selectCollect(shopcollect);

			if (usercollect != null) {
				EcpScUsercollect shop = new EcpScUsercollect();
				shop.setShopcolid(usercollect.getShopcolid());
				shop.setUserid(Integer.parseInt(userid));
				shop.setFid(shoppingcenterid);
				shop.setSort(2);
				shop.setTag(false);
				shop.setCollectdate(usercollect.getCollectdate());
				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				shop.setCancledate(formatter.format(new Date()));

				result = collectDao.updateCollect(shop);
			}

		}

		return result;
	}

	/**
	 * 查询某用户是否赞了某个新品
	 */
	@Override
	public boolean isApplaudNewProduct(String userid, String deviceid,
			String newproductId) {// 三十
		boolean result = false;

		if (userid != null && newproductId != null) {
			PraiseDaoImpl praiseDao = new PraiseDaoImpl();

			EcpPpPraise praise = new EcpPpPraise();
			praise.setUserid(Integer.parseInt(userid));
			praise.setBraotherid(Integer.parseInt(newproductId));

			result = praiseDao.checkPraise(praise);

		}

		return result;

	}

}
